#ifndef SHAPE_H_
#define SHAPE_H_

#include <assert.h>
#include <malloc.h>

#include "../logger.h"

/**
 * Abstract base class for all of the shapes in the game
 */
class AFShape
{
protected:
	float* _vertices;
	int _verticesCount;

protected:
	virtual void makeShape(float aspect) = 0;

public:
	AFShape() : _vertices(NULL), _verticesCount(0)
	{
	}

	virtual ~AFShape()
	{
		if (_vertices)
		{
			free(_vertices);
			_vertices = NULL;
			_verticesCount = 0;
		}
	}

	/**
	 * Vertex array for shape
	 */
	const float* getVertices() {return _vertices;}

	int getVerticesCount() {return _verticesCount;}
};


/**
 * The spaceship shape
 */
class AFSpaceship : public AFShape
{
protected:
	virtual void makeShape(float aspect)
	{
		assert(_vertices == NULL);

		int coords[] = {0, 5, 2, -3, 0, -1, -2, -3};
		int coordsLen = sizeof(coords) / sizeof(int);

		_vertices = (float*)malloc(sizeof(float) * coordsLen);
		_verticesCount = coordsLen / 2;

		if (_vertices)
		{
			for (int i = 0; i < coordsLen; i++)
				_vertices[i] = coords[i] * aspect;
		}
	}

public:
	AFSpaceship()
	{
		makeShape(0.01f);
	}
};

#endif /* SHAPE_H_ */
